import zlib

file_path = "output/1_res/jp"
file_names = ["CARD_Name"]


def 解密(file_name, m_iCryptoKey):
    with open(f"{file_path}/{file_name}", "rb") as f:
        data = bytearray(f.read())
    print(m_iCryptoKey)
    for i in range(len(data)):
        v = i + m_iCryptoKey + 0x23D
        v *= m_iCryptoKey
        v ^= i % 7
        data[i] ^= v & 0xFF
    zlib.decompress(data)


for name in file_names:
    for i in range(0xFF):
        m_iCryptoKey = i
        try:
            解密(name, m_iCryptoKey)
            print(f"{name} 解密成功，密钥为 {hex(m_iCryptoKey)}")
            break
        except Exception as e:
            pass
